package com.example.day10_cp;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class ContactAdapter extends BaseAdapter {
    List<Contact> list = new ArrayList<>();
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(convertView.getContext()).inflate(R.layout.activity_main,parent,false);
            convertView.setTag(new Viewholder(convertView));
        }
       /* Viewholder viewholder = (Viewholder) convertView.getTag();
        viewholder.name.setText(list.get(position).getName()+"");
        viewholder.number.setText(list.get(position).getNumber()+"");*/

        return convertView;
    }

    public void addAll(List<Contact> data){
        list.clear();
        list.addAll(data);
        notifyDataSetChanged();
    }

    public void add(Contact contact){
        list.add(contact);
        notifyDataSetChanged();
    }

    class Viewholder{
        TextView name,number;
        public Viewholder(View view){
           /* name = view.findViewById(R.id.name);
            number = view.findViewById(R.id.number);*/
        }
    }
}
